<?php
class Cellphonezone_Paymentmail_FormController extends Mage_Core_Controller_Front_Action{


    public function indexAction(){
      $this->loadLayout();
      $paymentForm = $this->getLayout()->createBlock('paymentmail/paymentform');
      $this->getLayout()->getBlock('content')->append($paymentForm);
      $this->renderLayout();
    }
     public function banktransferAction(){
      $this->loadLayout();
      $paymentForm = $this->getLayout()->createBlock('paymentmail/paymentform'); 
      $this->getLayout()->getBlock('content')->append($paymentForm);
      $this->renderLayout();
    }
    public function westernunionAction(){
        $this->loadLayout();
      $paymentForm = $this->getLayout()->createBlock('paymentmail/paymentform')->setTemplate('paymentemail/westernunionform.phtml'); ; 
      $this->getLayout()->getBlock('content')->append($paymentForm);
      $this->renderLayout();
     
    }
    public function moneygramAction(){
      $this->loadLayout();
      $paymentForm = $this->getLayout()->createBlock('paymentmail/paymentform')->setTemplate('paymentemail/moneygramform.phtml'); ; 
      $this->getLayout()->getBlock('content')->append($paymentForm);
      $this->renderLayout();
     
    }
    public function saveAction(){

        $data = $this->getRequest()->getParams();
        if(!empty($data)){
       
            if($data['type_fb_file']=='local'){
            
                    $uploader = new Mage_Core_Model_File_Uploader('file');
                    //$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png','bmp'));
                    $uploader->setAllowRenameFiles(true);
                    //$uploader->setFilesDispersion(true);
                    $result = $uploader->save( Mage::getBaseDir('var') . DS . 'paymentmail'.DS );
                    $data['file']= $result['file']; 
                   //var_dump($data);exit;    
            
            }
            unset($data['type_fb_file']);
            //$data['from_bank']='from_bank';
            //$data['to_bank']='to_bank';
            //$data['form_type']='form_type';
            $Paymentmail = Mage::getModel('paymentmail/paymentmail');
            $Paymentmail->setData($data);
            try{
                $Paymentmail->save();
                Mage::getSingleton('customer/session')->setPaymentmailData($data);  
            }catch(Exception $e){
               Mage::throwException($e->getMessage());exit;
               Mage::getSingleton('customer/session')->addError('error!,please submit again or go to <a class="my-link" rel="nofollow" href="http://www.support.sw-box.com">Support Ticket</a>');
            
            }
        }
       // echo '<pre>';var_dump($data);exit;
        $this->_redirect('*/*/return'); 
    
    }
     public function returnAction(){
      $this->loadLayout();
      $paymentForm = $this->getLayout()->createBlock('paymentmail/paymentform')->setTemplate('paymentemail/return.phtml'); 
      $this->getLayout()->getBlock('content')->append($paymentForm);
      $this->renderLayout();
     }

    public function testAction(){

        $http = new Varien_Http_Adapter_Curl();
        $config = array('timeout' => 30);
        $http->setConfig($config);
        $Query = array(
            'meta_web_form_id'=>'2031196674',
            'meta_split_id'=>'',
            'listname'=>'cpz-customers',
            'redirect'=>'http://www.sw-box.com/newsletter-submit.html',
            'meta_redirect_onlist'=>'http://www.sw-box.com/oops-already-subscribed-try-different-email-address-.html',
            'meta_adtracking'=>'sw-box.com',
            'meta_message'=>'1',
            'meta_required'=>'email',
            'meta_tooltip'=>'',
            'email'=>"lcb_wangyi2@163.com"
        );
        $Url = 'http://www.aweber.com/scripts/addlead.pl';
        $http->write(Zend_Http_Client::POST,$Url,'1.1',array(),http_build_query($Query));
        $response = $http->read();
        $http->close();
        echo $response;
    
    }
}
